﻿<Window x:Class="Demo.BehaviorsDemoWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:behaviors="clr-namespace:Thinktecture.UIAnnotations.Behaviors;assembly=Thinktecture.UIAnnotations"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        Title="Thinktecture.UIAnnotations Behavior Demo" Height="240" Width="325" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" 
        FontFamily="Calibri"  FontSize="14" TextOptions.TextRenderingMode="ClearType" TextOptions.TextFormattingMode="Display" UseLayoutRounding="True"
        FocusManager.FocusedElement="{Binding ElementName=idTextBox}">

    <Window.Resources>
        <Style TargetType="TextBox">
            <!--assign behavior in a style via BehaviorFactory-->
            <Setter Property="behaviors:BehaviorFactory.BehaviorTypeName" Value="Thinktecture.UIAnnotations.Behaviors.FocusBehavior" />
        </Style>
    </Window.Resources>

    <Grid x:Name="Main">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="12" />
            <ColumnDefinition Width="80" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="12" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="12" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="5" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="5" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="5" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="25" />
            <RowDefinition Height="12" />
        </Grid.RowDefinitions>

        <Label Grid.Column="1" Grid.Row="1" Content="ID:" />
        <TextBox Grid.Column="2" Grid.Row="1" x:Name="idTextBox" Text="{Binding Path=Person.Id, ValidatesOnDataErrors=True}">
            <i:Interaction.Triggers>
                <!--only accept numeric input-->
                <i:EventTrigger EventName="KeyDown">
                    <behaviors:NumericInputBehavior />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </TextBox>

        <Label Grid.Column="1" Grid.Row="3" Content="Firstname:" />
        <TextBox Grid.Column="2" Grid.Row="3" x:Name="firstNameTextBox"/>

        <Label Grid.Column="1" Grid.Row="5" Content="Lastname:" />
        <TextBox Grid.Column="2" Grid.Row="5"/>

        <Label Grid.Column="1" Grid.Row="7" Content="Image:" />
        
        <!--suppress FocusBehavior (which is assigned via style) for this control-->
        <TextBox Grid.Column="2" Grid.Row="7" x:Name="imageTextBox" IsReadOnly="True"
                 behaviors:BehaviorFactory.DetachBehaviorTypeName="Thinktecture.UIAnnotations.Behaviors.FocusBehavior">
            <i:Interaction.Behaviors>
                <!--assign watermark text via CueBannerAdorner-->
                <behaviors:CueBannerAdornerFactoryBehavior CueBannerText="Select an image!" />
            </i:Interaction.Behaviors>
        </TextBox>

        <Button x:Name="searchButton" Content="..." Width="20" Grid.Column="2" Grid.Row="7" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,2,0">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <!--show file open dialog and apply selection to textbox-->
                    <behaviors:OpenFileBehavior
                        TargetName="imageTextBox"
                        DialogTitle="Select an image..."
                        Filter="PNG Files|*.png" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>

        <StackPanel Grid.Column="2" Grid.Row="9" Orientation="Horizontal" HorizontalAlignment="Right">
            <Button x:Name="okButton" Content="OK" Width="80">
                <i:Interaction.Triggers>
                    <!--bind a command and if it is not present, hide the button-->
                    <i:EventTrigger EventName="Click">
                        <behaviors:CommandBehavior
                            Command="{Binding OkCommand}"
                            CommandAction="Hide" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <i:Interaction.Behaviors>
                    <behaviors:DialogButtonBehavior ButtonType="Ok" />
                </i:Interaction.Behaviors>
            </Button>

            <Button x:Name="cancelButton" Content="Cancel" Width="80" Margin="10,0,0,0">
                <i:Interaction.Behaviors>
                    <!--close the dialog (via mouse or esc-key) and set the DialogResult-->
                    <behaviors:DialogButtonBehavior ButtonType="Cancel" />
                </i:Interaction.Behaviors>
            </Button>
        </StackPanel>
        
        <CheckBox Name="busyCheckBox" Content="IsBusy" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="9" Height="16" HorizontalAlignment="Left" Margin="14,7,0,0" VerticalAlignment="Top">
            <i:Interaction.Behaviors>
                <!--show busy indicator-->
                <behaviors:BusyBehavior IsBusy="{Binding ElementName=busyCheckBox, Path=IsChecked}" />
            </i:Interaction.Behaviors>
        </CheckBox>
    </Grid>

    <Window.Background>
        <RadialGradientBrush>
            <GradientStop Color="White" Offset="0" />
            <GradientStop Color="#FFCDD6EF" Offset="1" />
        </RadialGradientBrush>
    </Window.Background>
</Window>
